#include <ctime>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

void bubbleSort(vector<int> list) {
    int listLength = list.size();
	while(listLength--) 	{
		bool swapped = false;
		
		for(int i = 0; i < listLength; i++) {
			if(list[i] > list[i + 1]){
				swap(list[i], list[i + 1]);
				swapped = true;
			}
		}	
	
		if(swapped == false) break;
	}
}

vector<int> read_from_file(const char *filename) {
    vector<int> result;
 
    ifstream in(filename);
    string toto;
    while (getline(in, toto))
    {
        result.emplace_back(stoi(toto));
    }
    
    in.close();
    return result;
}

int main()
{
    vector<int> m1 = read_from_file("m1_sorted.txt");
    int t_start =  clock();
    bubbleSort(m1);
    int timefin = clock();
    int timework = timefin - t_start;
    cout<<"m1_sorted " << round(timework * (1000.0 / CLOCKS_PER_SEC)) << " milliseconds \n";
    
    vector<int> m2 = read_from_file("m2_reverse.txt");
    t_start =  clock();
    bubbleSort(m2);
    timefin = clock();
    timework = timefin - t_start;
    cout<<"m2_reverse " << round(timework * (1000.0 / CLOCKS_PER_SEC)) << " milliseconds \n";
    
    vector<int> m3 = read_from_file("m3_shuffle.txt");
    t_start =  clock();
    bubbleSort(m3);
    timefin = clock();
    timework = timefin - t_start;
    cout<<"m3_shuffle " << round(timework * (1000.0 / CLOCKS_PER_SEC)) << " milliseconds \n";
    
    return 0;
}